package com.motorwaymanage.impl;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.motorwaymanage.beans.MaintainerInfo;
import com.motorwaymanage.biz.IMaintainerInfoBiz;
import com.motorwaymanage.dao.DBAccess;

public class MaintainerInfoBizImpl implements IMaintainerInfoBiz{
	private DBAccess db=new DBAccess();
	@Override
	public MaintainerInfo checkMaintainerLogin(MaintainerInfo mi) {
		SqlSession session=null;
		MaintainerInfo currentLogin=null;
		try {
			session=db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			currentLogin=maintainerInfoBiz.checkMaintainerLogin(mi);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return currentLogin;
	}
	
	@Override
	public MaintainerInfo selectOneStaff(int mid) {
		SqlSession session=null;
		MaintainerInfo oneMi=null;
		try {
			session=db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			oneMi=maintainerInfoBiz.selectOneStaff(mid);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return oneMi;
	}

	@Override
	public int updateStaffPwd(MaintainerInfo mi) {
		SqlSession session=null;
		int result=0;
		try {
			session=db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			result=maintainerInfoBiz.updateStaffPwd(mi);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	
	@Override
	public int addStaffInfo(MaintainerInfo mi) {
		SqlSession session=null;
		int result = 0;
		try {
			session = db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			result = maintainerInfoBiz.addStaffInfo(mi);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public int delStaffInfo(Integer mid) {
		SqlSession session=null;
		int result = 0;
		try {
			session = db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			result = maintainerInfoBiz.delStaffInfo(mid);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<MaintainerInfo> getAllStaff() {
		SqlSession session=null;
		List<MaintainerInfo> result = null;
		try {
			session = db.getSqlSession();
			IMaintainerInfoBiz maintainerInfoBiz=session.getMapper(IMaintainerInfoBiz.class);
			result = maintainerInfoBiz.getAllStaff();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
}
